import * as echarts from 'echarts'
import chinaMapData from '../data/china.json'

echarts.registerMap('china', chinaMapData)

export default function (el: HTMLElement) {
  const myEcharts = echarts.init(el)

  const setOptions = (options: echarts.EChartsOption) => {
    myEcharts.setOption(options)
  }

  const updateResize = () => {
    myEcharts.resize()
  }
  // 监听浏览器大小
  window.addEventListener('resize', () => {
    myEcharts.resize()
  })
  return {
    myEcharts,
    setOptions,
    updateResize
  }
}
